package com.daviteq.ems.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * Generic basic DAO
 * 
 * @author thanhthi.tran
 * @date Mar 28, 2014
 * @since 0.0.1
 * @param <T>
 * @param <K>
 */
public interface IBasicDAO<T, K extends Serializable> {

    /**
     * get an entity by identify
     * 
     * @param id
     * @return
     */
    public T findById(K id);

    /**
     * remove an entity by identify
     * 
     * @param id
     */
    public boolean remove(K id);

    /**
     * 
     * save an entity
     * 
     * @param t
     */
    public boolean persist(T t);
    
    /**
     * check exists of an identify by id
     * 
     * @param id
     * @return
     */
    public boolean exists(K id);
    
    /**
     * check exists of an identify by secondary index
     * 
     * @param colName
     * @param colValue
     * @return
     */
    public boolean existsSecondaryIndex(String colName, String colValue);
    
    /**
     * retrieve all secondary index
     * 
     * @param colName
     * @param colValue
     * @return
     */
    public List<T> findBySecondaryIndex(String colName, String colValue, String... colsRet);
    
    /**
     * partial update
     * 
     * @param cols
     * @param pks
     */
    public boolean updateMultiColsById(Map<String, Object> cols, String pk, String val);
    
    /**
     * retrieve all secondary index by multiple columns
     * 
     * @param colName
     * @param colValue
     * @return
     */
    public List<T> findBySecondaryIndexes(Map<String, Object> cols, String... colsRet);
    
    /**
     * retrieve all with limit
     * 
     * @param size
     * @return
     */
    public List<T> findAll(int size,  String... colsRet);
    
}
